package com.yulongtian.interviewWorks.day20220824;

import java.io.PrintWriter;

/**
 * @author YulongTian
 * @date 2022/8/24 - 11:02
 */
public class InterviewsWork02 {
    public static void main(String[] args) {
        //int[][] max = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}};
        //int[][] max = {{1, 2, 3}, {4,5,6}, {7,8,9}};
        int[][] max = {{1,2},{3,4}};
        rotate(max);

        for (int i = 0; i < max.length; i++) {
            for (int j = 0; j < max.length; j++) {
                System.out.print(max[i][j] + "\t");
            }
            System.out.println();
        }
    }

    public static void rotate(int[][] matrix) {
        int N = matrix.length;
        for (int i = 0; i < N / 2; i++) {
            for (int j = 0; j < N-2*i-1; j++) {
                //左上->右上  x,y -> y,N-x-1
                int pre = matrix[i][i + j];
                int later = matrix[i + j][N - i - 1];
                matrix[i + j][N - i - 1] = pre;
                //右上->右下
                pre = later;
                later = matrix[N - i - 1][N - i - j - 1];
                matrix[N - i - 1][N - i - j - 1] = pre;
                //3
                pre = later;
                later = matrix[N - i - j - 1][i];
                matrix[N - i - j - 1][i] = pre;
                //4
                pre = later;
                matrix[i][i + j] = pre;
            }
        }
    }


}
